<?php
/**
 * 跨域 post 请求
 * @param $url  远程接口地址
 * @param $data 提交的数据
 * @return 响应的数据
 */
function httpRequstPost($url,$data){
    $curl = curl_init();
    
    curl_setopt($curl, CURLOPT_URL,$url);

    curl_setopt($curl, CURLOPT_HEADER, 0);//设置header
    
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,true); //成功将结果返回，不自动输出任何内容
    
    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT,10); //告诉 PHP 在成功连接服务器前等待多久
    
    curl_setopt($curl, CURLOPT_POST,true); //启用POST提交

    curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($data));   // 提交
    
    $result = curl_exec($curl);
    
    curl_close($curl);

    return $result;
}

function getarticle($id){
    $url = "http://localhost:8080/Myblog/ReturnArticle";
    $data = array('id' => $id,);

    $result = httpRequstPost($url,$data);

    return $result;
}
/**
 * 查询文章的数量
 */
function getCountArticle(){
    $url = "http://localhost:8080/Myblog/ReturnCountArticle";

    $result = file_get_contents($url);

    return $result;
}

/**
 * 查询有哪些分类
 */
function getCategorys(){
    $url = "http://localhost:8080/Myblog/QueryCategory";
    $result = file_get_contents($url);
    return $result;
}

function getAllTitleList(){
    $url = "http://localhost:8080/Myblog/QueryTitleList";
    $result = file_get_contents($url);
    return $result;
}
/**
 * 传入inputCategory，获取指定列表
 */
function getTitleList($inputCategory){
    $url = "http://localhost:8080/Myblog/QueryTitleList";
    $result = httpRequstPost($url,$inputCategory);
    return $result;
}